package com.business.exam.service.impl;

import com.business.exam.mapper.IndexMapper;
import com.business.exam.service.IIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IndexServiceImpl implements IIndexService {
    @Autowired
    private IndexMapper indexMapper;
    /**
     * 首页-统计总览，查询考试场数、题库数量、试题总数
     * @param
     * @return
     */
    @Override
    public List<Map<String, Object>> selectStatisticsOverview() {
        return indexMapper.selectStatisticsOverview();
    }
    /**
     * 首页-进行中的考试
     * @param
     * @return
     */
    @Override
    public List<Map<String, Object>> selectOngoingExams() {
        return indexMapper.selectOngoingExams();
    }
    /**
     * 首页-考试总览
     * @param
     * @return
     */
    @Override
    public Map<String, Object> selectExamOverview() {
        List<Map<String, Object>> list =  indexMapper.selectExamOverview();
        Map<String, Object> mapData = new HashMap<String, Object>();
        List<String> xAxisData = new ArrayList<String>();
        List<String> examSessionData = new ArrayList<String>();
        List<String> examPeopleData = new ArrayList<String>();
        List<String> passPeopleData = new ArrayList<String>();
        if(null!=list){
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = list.get(i);
                xAxisData.add(String.valueOf(map.get("createTime")));
                examSessionData.add(String.valueOf(map.get("examSession")));
                examPeopleData.add(String.valueOf(map.get("examPeople")));
                passPeopleData.add(String.valueOf(map.get("passPeople")));
            }
        }
        mapData.put("xAxis",xAxisData);
        mapData.put("series0",examSessionData);
        mapData.put("series1",examPeopleData);
        mapData.put("series2",passPeopleData);
        return mapData;
    }
}
